package com.demo.jfinal.job;

import java.util.List;

import org.apache.log4j.Logger;

import com.demo.jfinal.model.ApiDownstream;
import com.demo.jfinal.model.GatewayConfig;

/**
 * 系统初始化缓存操作类
 * 
 */
public class CachetoReidsThread extends Thread {

	private static Logger log = Logger.getLogger(CachetoReidsThread.class);


	@Override
	public void run() {
		cacheAll();
	}

	/**
	 * 缓存所有参数
	 */
	public static synchronized void cacheAll() {
		log.info("缓存参数初始化 start ...");


		cacheDownstreamConfig();

		cacheGatewayConfig();
		
		
		log.info("缓存参数初始化 end ...");
	}


	/**
	 * 缓存所有客户
	 * 
	 */
	public static void cacheDownstreamConfig() {
		log.info("缓存加载：ApiDownstream start");
		List<ApiDownstream> lists = ApiDownstream.dao.find("select * from sms_api_downstream_config c where c.PROTOCOL_TYPE in ('1','2') ");
		for (ApiDownstream user : lists) {
			ApiDownstream.dao.cacheAdd(user.getInt("CONF_ID").toString());
			user = null;
		}
		log.info("缓存加载：ApiDownstream end, size = " + lists.size());
	}
	/**
	 * 缓存短信运营商配置
	 * GatewayConfig
	 */
	public static void cacheGatewayConfig() {
		log.info("缓存加载：GatewayConfig start");
		List<GatewayConfig> lists = GatewayConfig.dao.find("select * from sms_gateway_config");
		for (GatewayConfig user : lists) {
			GatewayConfig.dao.cacheAdd(user.getInt("ID").toString());
			user = null;
		}
		log.info("缓存加载：GatewayConfig end, size = " + lists.size());
	}


}
